namespace hemsidan.Entities
{
    using System;
    using System.Data;

    public class BlogComment
    {

        public static void Create(string CreatedBy, string Text, int BlogId)
        {

            string sql = "insert into BlogComments (BlogId, TextField, CreatedBy, Created) values (" + BlogId + ",'" + Text + "','" + CreatedBy + "','" + DateTime.Now + "')";
            DataAccess.DB db = DataAccess.DB.getInstance();
            db.ExecuteNonQuery(sql);
        }

        public static DataTable Get(int Id)
        {
            DataAccess.DB db = DataAccess.DB.getInstance();
            DataSet ds = db.ExecuteDataSet("select * from BlogComments where Id=" + Id.ToString());
            if (ds.Tables[0].Rows.Count < 1)
                throw new ApplicationException("Can not find blog comment");

            return ds.Tables[0];
        }


        public static void Delete(int Id)
        {
            DataAccess.DB db = DataAccess.DB.getInstance();
            db.ExecuteNonQuery("delete from BlogComments where Id=" + Id.ToString());
        }

        public static DataTable GetBlogsComments(int BlogId)
        {
            DataAccess.DB db = DataAccess.DB.getInstance();
            DataSet ds = db.ExecuteDataSet("select * from BlogComments where BlogId=" + BlogId.ToString() + " order by Created");
            return ds.Tables[0];
        }
    }
}